package calculadoraWeb;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name="calculadora",urlPatterns="/calculadora")

public class mostrarWeb extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		String a=req.getParameter("a");
		String b=req.getParameter("b");
		String operacion=req.getParameter("op");
		
		calcular[] operaciones={new suma(),new resta(),new multiplicar(),new division()};
		
		int op=Integer.parseInt(operacion);
		
		PrintWriter out = resp.getWriter();
		double result=operaciones[op].operar(Double.parseDouble(a), Double.parseDouble(b));
		String resultado=new Double(result).toString();
		
		out.println("<!DOCTYPE html>");
		out.println("<html>");
		out.println("<head>");
		out.println("<title>Calculadora</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>respuesta: </h1>");
		out.println("<h2>"+resultado+"</h2>");
		out.println("</body>");
		out.println("</html>");
		out.close();
	}	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}
	

}
